import java.util.Scanner;

public class ThreadDemo11 {

    volatile private static int flag;


    public static void main(String[] args) {

        Thread thread1 = new Thread(() -> {
            while(flag == 0) {
                //空循环
                System.out.println(flag);
            }
            System.out.println("thread1结束");
        });

        Thread thread2 = new Thread(() -> {
            Scanner sc = new Scanner(System.in);
            System.out.println("为flag赋值-》");
            flag = sc.nextInt();
        });

        thread1.start();
        thread2.start();
    }

}
